package com.zhuliwei.rabbitmq.direct.consumer;

import com.zhuliwei.domain.entity.Comment;
import com.zhuliwei.domain.entity.Notice;
import com.zhuliwei.mapper.NoticeMapper;
import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Date;

import static com.zhuliwei.constants.RabbitConstants.NOTICE_QUEUE2_NAME;

/**
 * Notice审核消息消费
 *
 * @author 朱力维
 * @time 2024/11/14 15:15
 **/
@Component
@RabbitListener(queues = NOTICE_QUEUE2_NAME)
public class NoticeAuditConsumer {
    @Resource
    private NoticeMapper noticeMapper;
    @RabbitHandler
    public void addAuditNotice(Comment comment){
        Notice notice = new Notice();
        if (comment.getStatus().equals("0")){
            //审核通过
            notice.setContent("您发表的内容：\""+comment.getContent()+"\"审核已通过");
        }else {
            //审核不通过
            notice.setContent("您发表的内容：\""+comment.getContent()+"\"审核未通过，请检查是否包含违规内容");
        }
        notice.setType("1");
        notice.setArticleId(comment.getArticleId());
        notice.setUserId(comment.getCreateBy());
        notice.setCreateBy("system");
        notice.setCreateTime(new Date());
        noticeMapper.insert(notice);
    }
}
